#ifndef __FINSH_H
#define __FINSH_H

#include "finsh_config.h"
#include "finsh_api.h"
#include "finsh_hw.h"

#include "loger.h"
#include "ringbuffer.h"
#include "os_sal.h"

#ifdef FINSH_CONSOLE_ENABLE
void _finsh_printf(const char *fmt, ...);
#endif


#define FINSH_PROMPT        finsh_get_prompt()
const char* finsh_get_prompt(void);
int finsh_set_prompt(const char * prompt);

/* system variable table */
struct finsh_sysvar
{
    const char*     name;       /* the name of variable */
#if defined(FINSH_DESCRIPTION_ENABLE) && defined(FINSH_SYMTAB_ENABLE)
    const char*     desc;       /* description of system variable */
#endif
    uint8_t      type;      /* the type of variable */
    void*        var ;      /* the address of variable */
};


#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__))
struct finsh_syscall* finsh_syscall_next(struct finsh_syscall* call);
struct finsh_sysvar* finsh_sysvar_next(struct finsh_sysvar* call);
#define FINSH_NEXT_SYSCALL(index)  index=finsh_syscall_next(index)
#define FINSH_NEXT_SYSVAR(index)   index=finsh_sysvar_next(index)
#else
#define FINSH_NEXT_SYSCALL(index)  index++
#define FINSH_NEXT_SYSVAR(index)   index++
#endif

/*  */

enum input_stat
{
    WAIT_NORMAL,
    WAIT_SPEC_KEY,
    WAIT_FUNC_KEY,
};

struct finsh_shell
{
	enum input_stat stat;
	
	uint8_t echo_mode:1;
	uint8_t prompt_mode: 1;
	
#ifdef FINSH_HISTORY_ENABLE
	uint16_t current_history;
    uint16_t history_count;

    char cmd_history[FINSH_HISTORY_LINES][FINSH_CMD_SIZE];
#endif	
	
	char line[FINSH_CMD_SIZE];
    uint8_t line_position;
    uint8_t line_curpos;
	
#ifdef FINSH_AUTH_ENABLE
    char password[FINSH_AUTH_PASSWORD_MAX];
#endif
};


extern struct finsh_sysvar *_sysvar_table_begin, *_sysvar_table_end;


/* func */

int finsh_system_init(void);


#endif
